// 寻找英文字母中最常的不重复的连续字符串
// @Author JackSpanrrows
// @Date 12/5/2020 12:00
// @CopyRight 借鉴慕课网案例

package suanfa

import "fmt"

func suanfa1() {
    fmt.Println(nonRepeatingSubStr("bbbabsabjioaudas"))
}

func nonRepeatingSubStr(s string) int {
    lastStr := make(map[byte]int)
    start := 0
    maxLenth := 0

    for i, ch := range []byte(s) {
        lastI, ok := lastStr[ch];if ok && lastI >= start {
            start = lastI + 1
        } 
        if lastStr[ch] >= start {
            start = lastStr[ch] + 1
        }
        if i - start + 1 > maxLenth {
            maxLenth = i - start + 1
        }
        lastStr[ch] = i
    }

    return maxLenth
}
